//  封装axios请求
import axios from 'axios'

async function axiosGet(url,target,...arg){
        if(arg.length === 0){
            return await axios.get(`${url}${target}`)
            .then(data=>{
                if(data.data.code === 200){
                    return data.data
                }
            },err=>{
                console.log(err)
            })
        }else if(arg.length === 1){
            return await axios.get(`${url}${target}?${arg[0]}`)
            .then(data=>{
                if(data.data.code === 200){
                    return data.data
                }
            },err=>{
                console.log(err)
            })
        }else {
            let params = ''
            for(let i=0; i<arg.length; i++){
                params += arg[i]+'&'
            }
            params = params.substr(0,params.length-1)
            return await axios.get(`${url}${target}?${params}`)
            .then(data=>{
                if(data.data.code === 200){
                    return data.data
                }
            },err=>{
                console.log(err)
            })
        }
}

export {
    axiosGet
}